<?php
//默认前台控制器
class indexController extends webpageController{
    //网站首页
    //###########################################
    public function index(){
        $Domain = $_SERVER['HTTP_HOST'];
        $condition['url'] = $Domain;
        $rel = $this->model->table('cms_language')->field('types,tpl_index')->where($condition)->find(); 
        if($rel['types'] || $rel['tpl_index']){
            $this->display($rel['tpl_index']);
        }else{
            $this->display('default/index');
        }
    }
    //网站频道显示
    //###########################################
    public function channel(){
        $cid = intval($_GET['cid']);
        $this->assign('cid', $cid); //当前栏目ID
        $rel = api('cms','api_ChannelLabel',array($cid));
        if($rel[0]['tpl_channel']){
            $info = $rel[0];
            $this->assign('channel', $info);
            $this->assign('channelurl', url('index/channel',array('cid'=>$info['id'])));
            $this->assign('listsurl', url('index/lists',array('cid'=>$info['id'])));
            $this->display($info['tpl_channel']);
        }else{
            $this->pageError();
        }
    }
    //网站栏目显示
    //###########################################
    public function lists(){
        $cid = intval($_GET['cid']);
        $this->assign('cid', $cid); //当前栏目ID
        $rel = api('cms','api_ChannelLabel',array($cid));
        if($rel[0]['tpl_list']){
            $info = $rel[0];
            $this->assign('lists', $info);
            $this->assign('channelurl', url('index/channel',array('cid'=>$info['id'])));
            $this->assign('listsurl', url('index/lists',array('cid'=>$info['id'])));
            $this->display($info['tpl_list']);
        }else{
            $this->pageError();
        } 
    }
    //网站栏目显示
    //###########################################
    public function page(){
        $uid = intval($_GET['uid']);
        $this->assign('uid', $uid); //当前栏目ID
        $info = api('cms','api_DiyPageRead',array($uid));
        if($info){
            $this->assign('page', $info);
            $this->assign('pageurl', url('index/page',array('uid'=>$info['id'])));
            $this->display($info['tpl_channel']);
        }else{
            $this->pageError();
        }
    }
    //网站内容..
    //###########################################
    public function read(){
        $fid = intval($_GET['fid']);
        $cid = intval($_GET['cid']);
        $this->assign('cid', $cid);  //当前栏目ID
        $this->assign('fid', $fid);  //当前内容ID
        $rel = api('cms','api_ChannelLabel',array($cid));
        if($rel[0]['tpl_content']){
            $info = $rel[0];
            //栏目信息
            $this->assign('channel', $info);
            $this->assign('channelurl', url('index/channel',array('cid'=>$info['id'])));
            //内容信息
            $read = api('cms','api_ArticleDisplay',array($fid,$cid));
            $this->assign('read',$read);
            $this->assign('readurl', url('index/read',array('cid'=>$info['id'],'fid'=>$read[0]['id'])));
            if($info['plus_mid']){
                $plus = api('cms','api_ArticleList_Plus',array($fid,$info['plus_mid']));
                $this->assign('exts', $plus);
                $this->assign('extsurl', url('index/exts',array('cid'=>$info['id'],'aid'=>$plus[0]['id']))); 
            }
            $this->display($info['tpl_content']);
        }else{
            $this->pageError();
        }
    }
    //内容扩展
    //###########################################
    public function exts(){
        $cid = intval($_GET['cid']);
        $aid = intval($_GET['aid']);
        $this->assign('cid', $cid);  //当前栏目ID
        $this->assign('aid', $aid);  //当前内容ID
        $rel = api('cms','api_ChannelLabel',array($cid));
        if($rel){
            $info = $rel[0];
            if($info['tpl_plus']){
                //栏目信息
                $this->assign('channel', $info);
                $this->assign('channelurl', url('index/channel',array('cid'=>$info['id'])));
                //扩展信息
                if($info['plus_mid']){
                    $reads = api('cms','api_ArticleDisplay_Plus',array($aid,$info['plus_mid']));
                    $this->assign('exts', $reads);
                    $this->assign('extssurl', url('index/reads',array('cid'=>$info['id'],'aid'=>$reads['id'])));
                }
                //内容信息
                if($reads){
                    $read = api('cms','api_ArticleDisplay',array($reads['fid'],$cid));
                    $this->assign('exts',$read);
                    $this->assign('extsurl', url('index/exts',array('cid'=>$info['id'],'aid'=>$read[0]['id']))); 
                }
                $this->display($info['tpl_plus']);
            }else{
                $this->pageMsg('连接页面未绑定模板,请联系网站管理员!');
            } 
        }else{
            $this->pageError();
        }
    }
}
